package com.mtsmda.java.json.jsonsimple;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

public class WriteJSONToFile {

	public static void main(String[] args) throws Exception {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put(new String("CountryName"), new String("Ispaniya"));
		jsonObject.put("FootballClubName", "Barcelona");
		jsonObject.put("PlayerNumberLeader", new Integer(10));

		JSONArray jsonArray = new JSONArray();
		jsonArray.add("Messi");
		jsonArray.add("Neymar");
		jsonArray.add("Suarez");

		jsonObject.put("Players", jsonArray);

		File fileJSON = new File("FootballClubs.json");
		if (!fileJSON.exists()) {
			fileJSON.createNewFile();
		}

		Writer fileWriter = new FileWriter(fileJSON);
		fileWriter.write(jsonObject.toJSONString());
		fileWriter.flush();
		fileWriter.close();

	}

}